# 函数的定义

def f():
    print("This is a function.")

def sum_2(a,b):  # 形式参数
    return a+b

def power(x,n=3):  # n:默认参数，缺省参数
    return x**n

def infos(name,age=24,gender="女"):
    return "大家好，我叫%s，我今年%d岁，我是一名%s生。"%(name,age,gender)

# 可变参数求和
def total(*args): # 在形参前面加上*，就是将函数的输入值变为一个元组进行操作
    result = 0
    for i in args:
        result += i
    return result

def total1(**kwargs): # 可变参数，接收字典
    for k,v in kwargs.items():
        print(k,v)

# 函数调用
f()

result = sum_2(8,6)  # 实际参数
print(result)

a = power(5,2)
b = power(3)
print(a)
print(b)

s = infos("mia",23,"女")
print(s)
lily = infos("lily")
print(lily)

result1 = total(1,2,3,4,5,6,7,8,9)
print(result1)
a = [1,2,3,4,5]
result2 = total(*a) # 对于形参为*args，传入列表时也需要带*拆包使用
print(result2)
d = {"name":"xiaoming","age":25}
total1(**d)
